<%--
  Created by IntelliJ IDEA.
  User: 52203
  Date: 2018/12/28
  Time: 8:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <script type="text/javascript" src="static/js/jquery-2.1.1.min.js"></script>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@include file="../layUI.jsp" %>
</head>
<body>
<h1></h1>
<form action="/page/bigclass/bigAdd.jsp" method="post">
    <input type="submit" value="添加大分类" class="layui-btn">
</form>
<table width="100%" style="text-align: center" class="layui-table">

    <tr>
        <th>大分类ID</th>
        <th>大分类名称</th>
        <th>大分类描述</th>
        <th colspan="2">操作</th>
    </tr>

    <tbody id="theBody">

    </tbody>


    <tr>
        <td colspan="5">
            <%@include file="../Page.jsp" %>
        </td>
    </tr>
</table>
<h3></h3>
<script type="text/javascript">
    //初始化数据
    var currentPage = 1;  //当前页码
    var totalPags;

    //过滤查询
    function searchBig(currentPage) {
        //    $.getJSON("/doBig", { "action": "BigQuerySell","currentPage": currentPage}, callback);
        $.ajax({
            "url": "/doBig",
            "type": "GET",
            "data": {"action": "BigQuerySell", "currentPage": currentPage},
            "dataType": "JSON",
            "success": callback,
            "error": function () {
                alert("发生异常，请与管理员联系")
            },
            "beforeSend": function () {
                $("h1").show();
                $("h1").html("正在加载，请稍后.....");
            },
            "complete": function () {
                $("h1").html("");
                $("h1").hide();

            }
        })

        //回调
        function callback(data) {
            $("#theBody").html("");
            if (data.list.length <= 0) {
                $("h3").html("没有大分类");
                $("table").hide();
            } else {
                $("table").show();
                $("h3").html("");
            }
            for (var i = 0; i < data.list.length; i++) {
                $("#theBody").append("<tr>" +
                    "<td>" + data.list[i].bigId + "</td>" +
                    "<td>" + data.list[i].bigName + "</td>" +
                    "<td>" + data.list[i].bigText + "</td>" +
                    "<td>" +
                    "<a href='/page/bigclass/bigUpdate.jsp?id=" + data.list[i].bigId + "'>编辑</a>" +
                    "&nbsp; &nbsp;&nbsp;" +
                    "<a href='javascript:void(0)' onclick='delSbig(" + data.list[i].bigId + ",this)'>删除</a>" +
                    "</td>" +
                    "</tr>")
            }
            $("#total").html(data.totalCount);
            $("#totalPages").html(data.totalPages);
            $("#pageNo").html(currentPage);
            $("#theBody tr:even").css("backgroundColor","#FFCCFF");
            $("#jump1").html("");
            for (var i = 1; i <= parseInt(data.totalPages); i++) {
                $("#jump1").append("<option name=\"op1\" value=\"" + i + "\">" + i + "页</option>")
            }
            totalPags = $("#totalPages").html();
            document.getElementsByName("op1")[currentPage - 1].selected = true;
        }
    }

    //初始化加载数据
    $(function () {
        searchBig(1);
        //首页
        $("#begin").click(function () {
            currentPage = 1;
            searchBig(currentPage);
            $("#pageNo").html(currentPage);
        })
        //上一页
        $("#prev").click(function () {
            currentPage = parseInt(currentPage) - 1;
            if (parseInt(currentPage) < 1) {
                alert("已经是第一页了")
            } else {
                searchBig(currentPage);
                $("#pageNo").html(currentPage);
            }
        })
        //下一页
        $("#next").click(function () {
            currentPage = parseInt(currentPage) + 1;
            if (parseInt(currentPage) > parseInt($("#totalPages").html())) {
                alert("已经最后一页了");
                return;
            } else {
                searchBig(currentPage);
                $("#pageNo").html(currentPage);
            }
        })
        //最后一页
        $("#end").click(function () {
            currentPage = parseInt($("#totalPages").html());
            searchBig(currentPage);
            $("#pageNo").html(currentPage);
        })
        //到第几页
        $("#jump").click(function () {
            currentPage = document.getElementById("jump1").value;
            searchBig(parseInt(currentPage));
            $("#pageNo").html(currentPage);
        })
    })

    //删除
    function delSbig(id, btn) {
        $.getJSON("/doBig", {"action": "delSbig", "id": id}, callback);

        function callback(data) {
            if (data.flag == "true") {
                var option = confirm("确认删除吗？");
                if (option) {
                    $(btn).parent().parent().remove();
                    alert("删除成功！");
                    location.href="/doBig?action=bigQuery";
                } else {
                    alert("您取消了删除！")
                }
            } else {
                alert("失败！不能删除包含小分类的大分类！")
            }
        }
    }
</script>

</body>
</html>
